package com.docjohnson.pamphlet.activities;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.VideoView;
import com.docjohnson.pamphlet.R;
import com.docjohnson.pamphlet.dialogs.Dialogs;
import com.docjohnson.pamphlet.utils.Utils;
import com.docjohnson.pamphlet.views.VideoPlayer;

import java.io.IOException;

public class VideoViewActivity extends DefaultActivity {

    VideoPlayer myVideoView;
    VideoViewActivity _this = this;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.videoview);

        myVideoView = (VideoPlayer)findViewById(R.id.videoView);
        MediaController mc = new MediaController(this);
        mc.setMediaPlayer(myVideoView);
        mc.setAnchorView(myVideoView);
        myVideoView.setMediaController(mc);

        ((Button)findViewById(R.id.closeVideoViewId)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        play();

    }

    private void play(){
        Dialogs.showProgressDialog(_this);
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    final String path = "http://www.opticrack.com/media/videos/converted/1176176.mp4";//Utils.getDataSource("http://daily3gp.com/vids/747.3gp");
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            myVideoView.setVideoPath(path);
                            myVideoView.requestFocus();
                            myVideoView.start();
                            Dialogs.closeProgressDialog(_this);
                        }
                    });
                } catch (Exception e) {
                    e.printStackTrace();
                    Dialogs.closeProgressDialog(_this);
                }
            }
        }).start();
    }
}
